/**
*  \file sdec.h
*
*  \brief Saturated decrement functions.
*
*  \author Michael J. Hohmann <michael.hohmann@linde-mh.de>
*
*
*/

#ifndef SDEC_H_INCLUDED
#define SDEC_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"

/*================================================[ inline functions ]================================================*/

/**
*  Saturated decrement U8
*
*  The function sdec_u8 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE U8 sdec_u8( U8 value )
{
   if( U8_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement UX8
*
*  The function sdec_ux8 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE UX8 sdec_ux8( UX8 value )
{
   if( UX8_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement S8
*
*  The function sdec_s8 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE S8 sdec_s8( S8 value )
{
   if( S8_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement SX8
*
*  The function sdec_sx8 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE SX8 sdec_sx8( SX8 value )
{
   if( SX8_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement U16
*
*  The function sdec_u16 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE U16 sdec_u16( U16 value )
{
   if( U16_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement UX16
*
*  The function sdec_ux16 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE UX16 sdec_ux16( UX16 value )
{
   if( UX16_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement S16
*
*  The function sdec_s16 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE S16 sdec_s16( S16 value )
{
   if( S16_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement SX16
*
*  The function sdec_sx16 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE SX16 sdec_sx16( SX16 value )
{
   if( SX16_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement U32
*
*  The function sdec_u32 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE U32 sdec_u32( U32 value )
{
   if( U32_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement UX32
*
*  The function sdec_ux32 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE UX32 sdec_ux32( UX32 value )
{
   if( UX32_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement S32
*
*  The function sdec_s32 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE S32 sdec_s32( S32 value )
{
   if( S32_MIN < value )
   {
      value--;
   }
   return value;
}

/**
*  Saturated decrement SX32
*
*  The function sdec_sx32 decrements the passed value as long as this does not underflow,
*  and returns it.
*
*   \param value Value to be decremented.
*
*   \return The decremented value.
*/
STATIC_INLINE SX32 sdec_sx32( SX32 value )
{
   if( SX32_MIN < value )
   {
      value--;
   }
   return value;
}

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2011 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
